
export const getMenuComponents = () => {
    const  components = ref([])
    const modules = import.meta.glob("@/views/**/**.vue");
    const whiteList = ['/src/views/error', '/src/views/login', '/src/views/dev'];
    f1:
        for (let key in modules) {
            for (let l1 in whiteList) {
                if (key.startsWith(l1))
                    break f1
            }
            modules[key].call().then((result) => {
                if (result.default.name) {
                    components.value.push({
                        name: result.default.name,
                        path: key.slice(11),
                    })
                }
            })
        }
    return components
}

export const arr2Tree = (arr, prk = "id", pik = "pid", ck = "children") => {
    const map = new Map();
    arr.forEach(item => {
        map.set(item[prk], {...item, [ck]: []});
    });

    const tree = [];
    map.forEach((item, key) => {
        if (item[pik] === 0 || !map.has(item[pik])) {
            tree.push(item);
        } else {
            const parent = map.get(item[pik]);
            parent[ck].push(item);
        }
    });

    return tree;
}

export const objMerge = (target, data, exclude = []) => {
    Object.keys(target).forEach(key => {
        if (key in data && data[key] && exclude.indexOf(key) === -1) {
            target[key] = data[key];
        }
    })
}